package com.zcy.utils;

import com.zcy.model.Brand;

import java.util.Random;

public class BrandUtils {
    //产生一个随机数
    public static Random random = new Random();
    //定义数组 保存卡牌信息
    private static String [] brandNames = {"刷子","剪刀","叉子","手套","水桶","火",
            "玉米","球","瓶子","白菜","稻草","肉腿","胡萝卜","苹果","铃铛","青草"};
    //定义一个方法获取卡牌名称
    public static String getBrandName(){
        int index = random.nextInt(brandNames.length);
        return brandNames[index];
    }
    //获取brand
    public static Brand [] builderBrand(int capacity){
        //实例化数组
        Brand [] brands = new Brand[capacity];
        for (int i = 0;i<brands.length;i += 3){
            //获取卡牌名称
            String brandsName = getBrandName();
            //实例化卡牌对象
            Brand b1 = new Brand(brandsName);
            Brand b2 = new Brand(brandsName);
            Brand b3 = new Brand(brandsName);
            //数组赋值
            brands[i] = b1;
            brands[i+1] = b2;
            brands[i+2] = b3;
        }
        //将元素进行随机置换
        for (int i = 0;i < brands.length; i++){
            //获取i元素 赋值给中间变量
            Brand brandA = brands[i];
            //产生随机索引 值交换
            int index = random.nextInt(brands.length);
            brands[i] =brands[index];
            brands[index]=brandA;
        }
        return brands;
    }
}
